<?php

namespace app\common\model;

use app\common\model\Common;
use think\model\concern\SoftDelete;
class ProductType extends Common
{
    // use SoftDelete;
    // protected $deleteTime = 'dele_time';
    protected  $table = 'product_type';

    // 指定允许批量赋值的字段
    protected $fillable = ['name',"update_at","store_id","parent_id","sort"];

     // 查询
     public function getProduct($pid = 0){

        $field = 'id,name,parent_id';
        $sort = 'sort '.$this->sysconfig['sort'];
        $where = [];
        $where[] = ['parent_id','=',$pid];
       
   
        $productList = $this->getAllOrder($where,$field,$sort)->toArray();
        // 判断是否有子集
        foreach($productList as &$v){
            $wherechild = ['parent_id'=>$pid];
            $has = $this->countRows($wherechild);
            if($has){
                $v['child'] = $this->getProduct($v['id']);
            }
        }
        return $productList;
    }
    
}